

<div style="width:670px; float:left; margin-right:5px" class="border_radius">

  <?php  	

  	include_once("../../coms/xl_danhmuc.php");

	include_once("../../include/convert_link.php");

	$dm = new xl_danhmuc();

	$arr_dmsp = array();

	if(isset($_REQUEST["query"]))

	{

		if($_REQUEST["query"] == "added")

		{

			$tendm = $_POST['txt_tendm'];	

			

			$conv = new convert_link();

			$tendanhmuc_convert = $conv->convert_vi_to_en($tendm);

			$tendanhmuc_convert = trim(strtolower($tendanhmuc_convert));

			

			$timezone  = +7; //(GMT +7:00) 

			$currentDate = gmdate("Y-m-d", time() + 3600*($timezone+date("0"))); 

			 

			$ketqua = $dm->Them_danh_muc($tendm,$currentDate,$tendanhmuc_convert,'','');

			echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=qldm"  />';

		}

		if($_REQUEST["query"] == "fixed")

		{

			$ma_dm = $_REQUEST["ma"];

			$tendm = $_POST['txt_tendm'];

			

			$conv = new convert_link();

			$tendanhmuc_convert = $conv->convert_vi_to_en($tendm);

			$tendanhmuc_convert = trim(strtolower($tendanhmuc_convert));

			

			$timezone  = +7; //(GMT +7:00) 

			$currentDate = gmdate("Y-m-d", time() + 3600*($timezone+date("0"))); 

			$ketqua = $dm->Cap_nhat_danh_muc($ma_dm,$tendm,$tendanhmuc_convert,$currentDate,'',1);

			echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=qldm"  />';

		}

		

		if($_REQUEST["query"] == "del")

		{

			$ma_dm = $_REQUEST["ma"];

			$ketqua = $dm->Xoa_danh_muc($ma_dm);				

		}						

	}	

	if(isset($_REQUEST["query"]) && $_REQUEST["query"] == "fix")

	{

		$dm_fix = new xl_danhmuc();	

		$ma_dm = $_REQUEST["ma"];

		$arr_sp = $dm_fix->Load_danh_muc_theo_ma($ma_dm);

	}

	else

	{

		$arr_dmsp = $dm->Load_danh_muc();

		

	}

?>
  
<div class="content_right_title_admin">
Quản lý danh mục
</div> 
  <div class="content_right_group_admin box_shadow">

    <div class="noidung_chitiet_tin" style="min-height:590px;">

    	<div align="right">

        	<?php

				if(!isset($_REQUEST["query"]) || $_REQUEST["query"] != "add")

					{

			  ?> 

						<div style="margin-left:10px; margin-right:5px" align="right"> 

							<input type="button" name="bt_taomoi" value="Tạo mới"  

								onClick="javascript:window.location='trangchu.php?key=qldm&query=add'" class="button small blue"/> 

						</div>

			   <?php

					}

			   ?>

        </div>

    	<table width="98%" border="1" style="margin:10px 20px 10px 10px; line-height:25px; border-color:#993300" cellspacing="0" id="myTable">

        	<tr bgcolor="#999999">

                <th>Tên danh mục</th>

                <th>Ngày tạo</th>

                <th>Chức năng</th>

            </tr>

            <?php

				$dem = 0;

				$start = 1;

				$limit = 10;

				$count = count($arr_dmsp);

				

				$pages = $count % $limit == 0 ? $count / $limit : ceil($count / $limit);

				

				if(isset($_GET["page"]))

					$start = ($_GET["page"] - 1) * $limit + 1;

					

				$end = ($start + $limit) <= $count ? $start + $limit : $count + 1;

				for($i = $start ; $i < $end; $i++)

            	//for($i=0;$i<count($arr_sp); $i++)

				{

					$row = $arr_dmsp[$i-1];

					if($i % 2 != 1)

						echo '<tr style="color:#000000">';

					else

						echo '<tr>';

					if($i % 2 == 1)

						echo '<td style="padding-left:10px;" class="chucnang1">';

					else

						echo '<td style="padding-left:10px;" class="chucnang">';

			?>



                	<a href="trangchu.php?key=qldv&madm=<?php echo $row['madanhmuc'] ?>"><?php echo $row['tendanhmuc'] ?></a>

                </td>

                <td align="center"><?php echo $row['ngaytao'] ?></td>

            <?php

				if($i % 2 == 1)

                	echo '<td align="center" class="chucnang1">';

				else

					echo '<td align="center" class="chucnang">';

			?>

            		<a href="trangchu.php?key=qldm&query=del&ma=<?php echo $row['madanhmuc'] ?> ?>" onClick=" return confirm('Bạn có thật sự muốn xóa sản phẩm này?')" class="button medium blue">Xóa</a> | <a href="trangchu.php?key=qldm&query=fix&ma=<?php echo $row['madanhmuc'] ?>" class="button medium blue"> Sửa</a></td>

            </tr>	

            <?php

            	}

			?>

        </table>

      <div class="phantrang">

      	<?php

		

			$self = $_SERVER["PHP_SELF"];

			$page = 0;

			if(isset($_GET["page"]))

				$page = $_GET["page"];

				

			$page_list = "";

			

			

			for($i=1; $i <= $pages; $i++)

			{

				$page_list .= "&nbsp;[&nbsp;<a href='$self?page=$i&key=qldm'>";

				if(isset($_GET["page"]))

				{

					if($page == $i)

						$page_list .= "<span style='font-size:1.1em; color:#fcf46f'><b>$i</b></span></a>&nbsp;]&nbsp;";

					else

						$page_list .= "$i</a>&nbsp;]&nbsp;";

				}

				else

					$page_list .= "$i</a>&nbsp;]&nbsp;";

			}

			echo $page_list;

			

		?>

      </div> 

      

       <div>       

	<?php

			

		if(isset($_REQUEST["query"]))

		{

			if($_REQUEST["query"] == "add")

			{

				

	?>

    <div align="center">

    <form name="fr_them" method="post" action="trangchu.php?key=qldm&query=added" enctype="multipart/form-data">

    	<table width="90%" align="center" cellpadding="10px" cellspacing="10">

        	<tr>

            	<td>Tên danh mục</td>

                <td><input type="text" name="txt_tendm" value="" size="60" class="border_radius"/></td>

            </tr>

            <tr>

            	<td colspan="2" align="center">

                	

                	<input type="submit" name="bt_capnhat" value="Tạo mới" class="button small blue"/>

                     &nbsp;&nbsp;&nbsp;<input type="button" name="bt_lamlai" value="Quay lại"  onClick="javascript:window.location='trangchu.php?key=qldm'" class="button small blue"/>

                </td>

            </tr>

        </table>

    </form>

    <div>

    <?php

			}

			if($_REQUEST["query"] == "fix")

			{

	?>

    <div align="center">

    <form name="fr_sua" method="post" action="trangchu.php?key=qldm&query=fixed&ma=<?php echo $arr_sp['madanhmuc']?>" enctype="multipart/form-data">

    	<table width="80%" align="center" cellpadding="10px" cellspacing="10" >

        	<tr>

            	<td>Tên danh mục</td>

                <td><input type="text" name="txt_tendm" value="<?php echo $arr_sp['tendanhmuc'] ?>" size="60" class="border_radius"/></td>

            </tr>

            <tr>

            	<td colspan="2" align="center">

                	

                	<input type="submit" name="bt_capnhat" value="Cập nhập" class="button small blue"/>

                    &nbsp;&nbsp;&nbsp;<input type="button" name="bt_lamlai" value="Quay lại"  onClick="javascript:window.location='trangchu.php?key=qldm'" class="button small blue"/>

                </td>

            </tr>

            <tr>

                <td >

                	<input type="hidden" name="txt_madanhmuc" value="<?php echo $arr_sp['madanhmuc'] ?>" />

                    

                </td>

            </tr>

        </table>

    </form>

    <div>

    <?php

			}

		}

	?>

    </div>

    </div>

   

  </div>

</div>

</div>

</div>